package com.ruoyi.web.controller.inv;

import com.ruoyi.buy.domain.entity.PO.InvTransboundBill;
import com.ruoyi.buy.domain.entity.inv0009.Inv0009UpdateByIdVO;
import com.ruoyi.buy.service.IInvTransboundBillService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 调拨单Controller
 * 
 * @author panghai
 * @date 2024-01-09
 */
@RestController
@RequestMapping("/inv/invTrans")
@Transactional
public class InvTransboundBillController extends BaseController
{
    @Autowired
    private IInvTransboundBillService invTransboundBillService;

    /**
     * 查询调拨单列表
     */

    @GetMapping("/list")
    public TableDataInfo list(InvTransboundBill invTransboundBill)
    {
        startPage();
        List<InvTransboundBill> list = invTransboundBillService.selectInvTransboundBillList(invTransboundBill);
        return getDataTable(list);
    }

    /**
     * 导出调拨单列表
     */
    @Log(title = "调拨单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvTransboundBill invTransboundBill)
    {
        List<InvTransboundBill> list = invTransboundBillService.selectInvTransboundBillList(invTransboundBill);
        ExcelUtil<InvTransboundBill> util = new ExcelUtil<InvTransboundBill>(InvTransboundBill.class);
        util.exportExcel(response, list, "调拨单数据");
    }

    /**
     * 获取调拨单详细信息
     */
    @PostMapping(value = "getInfo")
    public AjaxResult getInfo(@RequestBody InvTransboundBill invTransboundBill)
    {
        return success(invTransboundBillService.selectInvTransboundBillById(invTransboundBill.getId()));
    }

    /**
     * 新增调拨单
     */
    @Log(title = "调拨单新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Inv0009UpdateByIdVO para)
    {
        return toAjax(invTransboundBillService.insertInvTransboundBill(para));
    }

    /**
     * 修改调拨单
     */
    @Log(title = "调拨单修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Inv0009UpdateByIdVO para)
    {
        return toAjax(invTransboundBillService.updateInvTransboundBill(para));
    }

    /**
     * 删除调拨单
     */
    @Log(title = "调拨单删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invTransboundBillService.deleteInvTransboundBillByIds(ids));
    }

    @PostMapping(value = "/getWhlist")
    public AjaxResult getWhlist()
    {
        return success(invTransboundBillService.getWhlist());
    }

    /**
     * 修改调拨单
     */
    @Log(title = "调拨单执行", businessType = BusinessType.UPDATE)
    @PostMapping("/excuteDB")
    public AjaxResult excuteDB(@RequestBody Inv0009UpdateByIdVO para) throws Exception {
        return toAjax(invTransboundBillService.excuteTrans(para));
    }

}
